<template>
  <div>
    <div id="search">
      <el-form :inline="true" :model="CourseSearch" class="demo-form-inline">
        <el-form-item label="用户名">
          <el-input v-model="CourseSearch.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  icon="el-icon-search" @click="onSearchSubmit">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div id="header-bth">
      <el-button icon="el-icon-delete" type="danger" plain size="mini"
                 :disabled="this.multipleSelection.length>0?false:true"  @click="deleteAll">删除
      </el-button>
    </div>
    <div id="role-table">
      <el-table
          :header-cell-style="{background:'rgb(242, 242, 242)'}"
          style="width: 100%;
          text-align: center"
          :data="tableData"
          :row-style="{height: '50px'}"
          :cell-style="{padding: '0'}"
          @selection-change="handleSelectionChange"
      >
        <el-table-column
            type="selection"
            width="55"
            align="center"
        >
        </el-table-column>
        <el-table-column label="操作人">
          <template slot-scope="scope">
            <span>{{ scope.row.username}}</span>
          </template>
        </el-table-column>
        <el-table-column label="IP">
          <template slot-scope="scope">
            <span>{{ scope.row.ip}}</span>
          </template>
        </el-table-column>
        <el-table-column label="参数"  width="200"  :show-overflow-tooltip='true'>
          <template slot-scope="scope">
            <span>{{ scope.row.params}}</span>
          </template>
        </el-table-column>
        <el-table-column label="资源路径">
          <template slot-scope="scope">
            <span>{{ scope.row.url}}</span>
          </template>
        </el-table-column>
        <el-table-column label="描述">
          <template slot-scope="scope">
            <span>{{ scope.row.description}}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" >
          <template slot-scope="scope">
            <span>{{ scope.row.createTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="模块">
          <template slot-scope="scope">
            <span>{{ scope.row.model}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
                size="mini"
                type="danger"
                icon="el-icon-delete"
                @click="handleDelete(scope.row.id)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div id="nav-page">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="pageSizes"
          :current-page="CourseSearch.page"
          :page-size="CourseSearch.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import instance from "@/request/request";

export default {
  data() {
    return {
      tableData: [],
      pageSizes: [10, 15, 20],
      total: 0,
      CourseSearch: {  // 搜索数据
        page: 1,
        limit: 10
      },
      multipleSelection:[]
    }
  },
  created() {
    this.getscoreList()
  },
  methods: {
    //获取角色信息
    getscoreList() {
      instance.get("/log/getlist",{params:this.CourseSearch}).then(res=>{
        if(res.code==200){
          this.tableData=res.data.log
          this.total=res.data.total
          return
        }
        this.$message.error(res.msg)
      }).catch(erro=>{
        this.$message.error("请求失败！")
      })
    },
    deleteAll(){
      this.$confirm('确认要删除？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        instance.delete("/log/delete",{data:this.multipleSelection}).then(res=>{
          if(res.code==200){
            this.$message.success(res.msg)
            this.getscoreList()
            return
          }
          this.$message.warning(res.msg)
        }).catch(erro=>{
          this.$message.error("请求失败！")
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        })
      })
    },
    // 删除角色
    handleDelete(id) {
      this.$confirm('确认要删除？', '系统提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const ids=[id]
        instance.delete("/log/delete",{data:ids}).then(res=>{
          if(res.code==200){
            this.$message.success(res.msg)
            this.getscoreList()
            return
          }
          this.$message.warning(res.msg)
        }).catch(erro=>{
          this.$message.error("请求失败！")
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消！'
        })
      })
    },
    // 搜索角色
    onSearchSubmit() {
      this.CourseSearch.page = 1
      this.CourseSearch.limit = 10
      this.getscoreList()
    },
    // 改变每页显示的条数触发
    handleSizeChange(val) {
      this.CourseSearch.limit = val;
      this.getscoreList()
    },
    // 改变页码触发
    handleCurrentChange(val) {
      this.CourseSearch.page = val;
      this.getscoreList()
    },
    handleSelectionChange(val){
      this.multipleSelection=val.map(s=>s.id)
    }
  },
}
</script>

<style scoped>
#search {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid #eee;
}

#search, #header-bth, #nav-page {
  margin: 15px;
}

#role-table {
  width: 100%;
}
</style>
